Imports adsiClass
Imports System.Data
Imports System.Data.OleDb
Imports System.DirectoryServices
Imports System.Security.Cryptography

Partial Class mpAdmin
    Inherits System.Web.UI.MasterPage

    Dim ad As New adsiClass
    Dim cr As New Crypto

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim LoginName As String = ad.ExtractUserNameFromLoginName(cr.Decrypt(Session("user").ToString(), "key1!"))
        Dim result As SearchResult
        ad.userName = cr.Decrypt(Session("user").ToString(), "key1!")
        ad.userPassword = cr.Decrypt(Session("pas").ToString(), "key1!")
        '''''''Declare Username and Password before you make this object...
        Dim de As DirectoryEntry = ad.GetDirectoryEntry("LDAP://" & cr.Decrypt(Session("dc").ToString, "key1!") & "")
        Dim dsh As New DirectorySearcher(de)
        dsh.SearchScope = SearchScope.Subtree
        dsh.Filter = "(&(objectClass=user) (sAMAccountName=" & LoginName & "))"
        Try
            result = dsh.FindOne()
            Dim isAdmin As Boolean = ad.UserExistInGroup(de, result.Path, "Domain Admins")
            If isAdmin = True Then

            ElseIf isAdmin = False Then
                Response.Redirect("~/wpAdminLogin.aspx")
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub lblMasterSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblMasterSearch.Click
        Response.Redirect("~/wpAdminSearch.aspx")
    End Sub

    Protected Sub lblMasterLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblMasterLogout.Click
        Session.Abandon()
        Response.Redirect("~/wpAdminLogin.aspx")
    End Sub
End Class

